{extend name="property/public/insidePageBase" /}
{block name="title"}项目详情{/block}
{block name="body"}

<div class="layuimini-container">
    <div class="layuimini-main">
        <div class="layui-form  layui-form-pane">
            <div class="layui-tab layui-tab-brief" lay-filter="docDemoTabBrief">
                <div class="layui-tab layui-tab-brief">
                    <!--基本信息 add-->
                    <div class="layui-row">
                        <div class="layui-col-xs6">
                            <div class="layui-form-item">
                                <label class="layui-form-label">巡检位置</label>
                                <div class="layui-input-block">
                                    <input type="text" value="{$info['property_name'] ?? ''}   {$info['site_name'] ?? ''}" disabled autocomplete="off" class="layui-input">
                                </div>
                            </div>
                        </div>
                        <div class="layui-col-xs6">
                            <div class="layui-form-item" pane="">
                                <label class="layui-form-label">启用状态 </label>
                                <div class="layui-input-block">
                                    <input type="checkbox" lay-skin="switch"  disabled lay-filter="status" {:isset($info['is_show']) ? $info['is_show'] == 1 ? 'checked' : '' : ''} lay-text="启用|禁用" />
                                </div>
                            </div>
                        </div>
                    </div>
                    <form class="layui-form  layui-form-pane" action="">
                        <div class="layui-inline">
                            <label class="layui-form-label">按类目筛选</label>
                            <div class="layui-input-inline" style="width: 158px;">
                                <select name="cate_name">
                                    <option value="">--请选择--</option>
                                    {if $info['attr_value']}
                                    {foreach $info['attr_value'] as $k=>$v}
                                    <div class="layui-col-xs3">
                                        <option value="{$v['name']}">{$v['name']}</option>
                                    </div>
                                    {/foreach}
                                    {/if}
                                </select>
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label">关键字搜索</label>
                            <div class="layui-input-inline">
                                <input type="text" name="keywords" autocomplete="off" class="layui-input" placeholder="项目名称关键字" >
                            </div>
                        </div>
                        <div class="layui-inline">
                            <button type="submit" class="layui-btn layui-btn-primary"  lay-submit lay-filter="data-search-btn"><i class="layui-icon"></i> 搜 索</button>
                        </div>
                    </form>
                    <script type="text/html" id="toolbar">
                        <div class="layui-btn-container">
                            {if $addAuth} <button class="layui-btn layui-btn-normal layui-btn-sm data-add-btn" lay-event="addLogs"> 添加巡检记录 </button> {/if}
                            {if $delAuth}<button class="layui-btn layui-btn-sm layui-btn-danger data-delete-btn" lay-event="delete"> 删除 </button>{/if}
                        </div>
                    </script>
                    <table class="layui-hide" id="productFollowUpList" lay-filter="productFollowUpList"></table>
                    <script type="text/html" id="status_tpl">
                        {{# if(d.status === 1) { }}<span class="layui-badge layui-bg-blue">正常</span>{{# } }}
                        {{# if(d.status === 2) { }}<span class="layui-badge layui-bg-red">异常</span>{{# } }}
                    </script>
                    <script type="text/html" id="pictures_tpl">
                        {{# layui.each(d.pictures, function(index,item) { }}
                            <img src="{{ item }}" class="checkPictureByImg" style="width: 30px;height:30px;" alt="">
                        {{# }) }}
                    </script>
                    <!--基本信息 add-->
                </div>
            </div>
        </div>
    </div>
</div>
{/block}
{block name="js"}
{__block__}
<script>
    layui.use(['form', 'layer', 'table'], function () {
        var form = layui.form, layer = layui.layer, $ = layui.$, table = layui.table;
        let siteId = {$info['id']};
        var tableId = 'productFollowUpList';
        table.render({
            elem: '#' + tableId,
            id: tableId,
            url: '{:url("propertyInspectionLogList")}?site_id='+siteId,
            toolbar: '#toolbar',
            cols: [[
                {type: 'checkbox', fixed: 'left', rowspan: 2},
                {field: 'add_time', width: 168,title: '巡检时间', sort: true},
                {field: 'cate_name', width: 168, title: '巡检类目', sort: true},
                {field: 'status',  title: '巡检情况', width: 90, templet:'#status_tpl', align: "center"},
                {field: 'pictures',  title: '图片', width: 198, templet:'#pictures_tpl'},
                {field: 'remark', minWidth: 168, title: '备注说明'},
            ]],
            limits: [10, 15, 20, 25, 50, 100],
            limit: 16,
            page: true,
            height: 'full-120'
        });
        form.on('submit(data-search-btn)', function (data) {  table.reload(tableId, {page: { curr: 1  }, where: data.field}, 'data'); return false; });
        table.on('toolbar('+tableId+')', function (obj) {
            if (obj.event === 'addLogs') {  // 监听添加操作
                var url = '{:url("propertyInspectionLogAdd")}?site_id='+siteId;
                var index = layer.open({title: '添加', type: 2, shade: 0.2,maxmin:true, area: ['680px', '95%'], content: url, btnAlign: 'c', btn: ['确定', '取消'], yes: function (index, layero) {
                        var iframeWindow = window['layui-layer-iframe' + index], submit = layero.find('iframe').contents().find("#submitBtn");
                        iframeWindow.layui.form.on('submit(submitBtn)', function (data) {
                            var field = data.field; //获取提交的字段
                            var loadAdd = layer.msg('提交中', {icon: 16, time: 0, shade: 0.1, offset: '15px'});
                            $.post(url, field, function (res) {
                                layer.close(loadAdd);
                                if (res.code === 0) {
                                    table.reload(tableId); //数据刷新
                                    layer.close(index); //关闭弹层
                                    layer.msg(res.msg, {icon: 6, offset: '15px'});
                                } else {
                                    layer.msg(res.msg, {icon: 5, offset: '15px'});
                                }
                            });
                        });
                        submit.trigger('click');
                    }
                });
                $(window).on("resize", function () {
                    layer.full(index);
                });
            } else if (obj.event === 'delete') {  // 监听删除操作
                var checkStatus = table.checkStatus(obj.config.id),data = checkStatus.data;
                var data = checkStatus.data, id = [];
                for (elem in data) {
                    id.push(data[elem].id);
                }
                if (id.length === 0) {
                    return layer.msg('请选择要删除的数据');
                }
                var url = '{:url("propertyInspectionLogDel")}';
                layer.confirm('删除后不可恢复！  是否确认? ', {icon: 3}, function () {
                    var loadAdd = layer.msg('提交中', {icon: 16, time: 0, shade: 0.1, offset: '15px'});
                    $.post(url, {ids: id}, function (res) {
                        layer.close(loadAdd);
                        if (res.code === 0) {
                            table.reload(tableId); //数据刷新
                            layer.msg(res.msg, {icon: 6, offset: '15px'});
                        } else {
                            layer.msg(res.msg, {icon: 5, offset: '15px'});
                        }
                    });
                });
            }
        });
    });
</script>
{/block}